package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * TODO
 *
 * @Author mr.zhang
 * Date 2025/5/29 1:58
 */
@Mapper
public interface ShoppingCartMapper {
    /**
     * 购物车数据批量添加到数据库
     * @param shoppingCartList
     */
    void batchInsert(List<ShoppingCart> shoppingCartList);

    /**
     * 根据传入shoppingCart进行条件查询
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 对于新添加的,进行更新
     * @param shoppingCart
     */
    @Update("update shopping_cart set number=#{number} where id=#{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    /**
     * 新增数据到购物车
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) " +
            "values (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 查看购物车
     * @return
     */
    @Select("select * from shopping_cart where user_id=#{userId}")
    List<ShoppingCart> showShoppingCart(@Param("userId") Long userId);

    /**
     * 清空购物车
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void cleanShoppingCart(@Param("userId") Long userId);
}
